﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace linkouqs.Gamekit {

    public sealed class CharacterAbilityPush : CharacterAbility {

        public PushableObject PushableObject { get; private set; }

        public void OnSelect(PushableObject pushableObject) {
            PushableObject = pushableObject;
        }

        public void OnUnselect(PushableObject pushableObject) {
            if (PushableObject == pushableObject) {
                if (IsInAnimation) {
                    PushableObject.OnStopPush();
                }
                PushableObject = null;
            }
        }

        public override bool CanStartAction() {

            if (IsInAnimation) {
                return false;
            }

            if (PushableObject == null) {
                //Debug.LogWarning("PushableObject == null");
                return false;
            }

            if (!PushableObject.CanPush(this)) {
                return false;
            }

            return true;
        }


        public override void StartAction() {
            base.StartAction();

            Character.Animator.SetTrigger("Push");
            PushableObject.OnStartPush(this);
        }

        public override void StopAction() {

            Character.Animator.SetTrigger("PushEnd");

            if (PushableObject != null) {
                PushableObject.OnStopPush();
            }
            base.StopAction();

        }

    }


}

